package com.liang.controller;


import com.liang.pojo.Reportforms;
import com.liang.empty.Result;
import com.liang.pojo.dto.ReportformsDto;
import com.sun.org.apache.xpath.internal.operations.Bool;
import org.springframework.web.bind.annotation.*;
import java.util.Map;
import java.util.HashMap;
import org.springframework.beans.factory.annotation.Autowired;;
import java.util.List;
import com.liang.service.ReportformsService;
/**
 *@作者:lsk
 *Controller接口
 *@Date:2023/10/26
*/
@RestController
@RequestMapping("/ReportformsURL")
public class ReportformsController {


	@Autowired
	private ReportformsService reportformsservice;


	/**
	根据Reportforms_id查询
	*/
	@GetMapping("/selectByReportforms_id/{reportforms_id}")
	public Result selectByReportforms_id(@PathVariable(value = "reportforms_id") Long reportforms_id){
		return Result.buildMessage(reportformsservice.selectByReportforms_id(reportforms_id),"查询成功",200);
	}


	/**
	根据Reportforms_id更新
	*/
	@PostMapping("/updateByReportforms_id")
	public Result updateByReportforms_id(@RequestBody Reportforms demo){
		return Result.buildMessage(reportformsservice.updateByReportforms_id( demo),"修改成功",0);
	}



	/**
	根据Reportforms_id删除
	*/
	@GetMapping("/deleteByReportforms_id/{reportforms_id}")
	public Result deleteByReportforms_id(@PathVariable(value = "reportforms_id") Long reportforms_id){
		return Result.buildMessage(reportformsservice.deleteByReportforms_id(reportforms_id),"删除成功",0);
	}





	/**
	 insert:(插入)
	*/
	@PostMapping("/insert")
	public Result insert(@RequestBody Reportforms demo){
		Result.buildSuccess(reportformsservice.insert(demo));
		return Result.buildMessage(demo,"添加成功",0);
	}



	/**
	 insertOrUpdate(插入或更新(根据主键或唯一索引更新，主键和唯一索引不会改变))
	*/
	@PostMapping("/insertOrUpdate")
	public Result insertOrUpdate(@RequestBody Reportforms demo){
		return Result.buildMessage(reportformsservice.insertOrUpdate(demo),"插入或更新成功",200);
	}



	/**
	 insertBath:(批量插入)
	*/
	@PostMapping("/insertBatch")
	public Result insertBatch(@RequestBody List<Reportforms> list){
		return Result.buildMessage(reportformsservice.insertBatch(list),"批量插入成功",200);
	}



	/**
	 insertOrUpdateBatch:(批量插入或更新)
	*/
	@PostMapping("/insertOrUpdateBatch")
	public Result insertOrUpdateBatch(@RequestBody List<Reportforms> list){
		return Result.buildMessage(reportformsservice.insertOrUpdateBatch(list),"批量更新成功",200);
	}



	/**
	 selectList:(根据参数查询集合)
	*/
	@PostMapping("/selectList")
	public Result selectList(@RequestBody Map<String,Object> param){
		Map map = new HashMap<String,Object>();
		if(param.get("pageNum") != null){
			map.put("total",reportformsservice.selectCount(param));
		}
		map.put("data",reportformsservice.selectList(param));
		return Result.buildMessage(map,"查询成功",200);
	}



	/**
	 selectCount:(根据集合查询数量)
	*/
	@PostMapping("/selectCount")
	public Result selectCount(@RequestBody Map<String,Object> param){
		return Result.buildMessage(reportformsservice.selectCount(param),"查询数量成功",200);
	}


	/**
	 * 添加报表信息
	 * @param reportforms
	 * @return
	 */
	@PostMapping("/addReportForms")
	public Result addReportForms(@RequestBody Reportforms reportforms){
		Boolean b =  reportformsservice.addReportForms(reportforms);
	 if(b) return Result.buildSuccess();
	 else return  Result.buildFail(1,"服务器繁忙");
	}
	/**
	 *获取本单位的信息列表，多条件查询，根据type，opinion，pulish_time,user_name
	 */
	@PostMapping("/GetReportFormsHistory")
	public Result GetReportForms(@RequestBody ReportformsDto reportformsDto){

	Map map = reportformsservice.GetReportFormsHistory(reportformsDto);

	return Result.buildSuccess(map);
	}


	/**
	 * 获取上级等待审批的报表 //根据名字，和申请时间审批
	 * @param reportformsDto
	 * @return
	 */
	@PostMapping("/superiorAplyReportForms")
	public  Result superiorAplyReportForms(@RequestBody ReportformsDto reportformsDto){

		Map map = reportformsservice.superiorAplyReportForms(reportformsDto);
		return Result.buildSuccess(map);
	}

	/**
	 * 上级审批操作  //需要参数opinion，reportforms_id
	 */
	@PostMapping("/superiorApprovalReportForms")
	public Result superiorApprovalReportForms(@RequestBody ReportformsDto reportformsDto){
	Boolean bit = 	reportformsservice.superiorApprovalReportForms(reportformsDto);
	if(bit) return  Result.buildSuccess();
	else return  Result.buildFail(1,"服务器繁忙!!!");
	}

	/**
	 * 民兵获取自己接收到的报表,条件查询 根据发布人员名字，和申请时间审批
	 */
	@PostMapping("/getReportForms")
	public  Result getReportForms(@RequestBody ReportformsDto reportformsDto){

	 Map map =	reportformsservice.getReportForms(reportformsDto);
	 return Result.buildSuccess(map);
	}

	/**
	 * 师师武装部、军事部可查询。根据发布人员名字，发布时间查询
	 * @param reportformsDto
	 * @return
	 */
	@PostMapping("/getAllReportForms")
	public Result getAllReportForms(@RequestBody  ReportformsDto reportformsDto){

	 Map map =	reportformsservice.getAllReportForms(reportformsDto);

	 return Result.buildSuccess(map);
	}
}